<?php

namespace App\Dao\Question;

use App\Model\Question\Question;
use \Yj\Daos\BaseDao;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;

/**
 * @var Question
 */
class QuestionDao extends BaseDao
{

    public function DaoWhere(array $params)
    {
        return $this->getDaoQuery($params, function (Verify $verify) {
            $verify('id', function (Builder $query, $id) {
                $query->where('id', $id);
            });
            $verify('title', function (Builder $query, $title) {
                $query->where('title', 'like', '%' . $title . '%');
            });
        });
    }

    public function setField(int $id, string $field, int $value)
    {
        $data = $this->where('id', $id)->firstOrError();
        $update = [$field => $value];
        $data->fill($update);
        return $data->save();
    }

}
